#ifndef MEDIAENC_H
#define MEDIAENC_H
#include "ldCommInc.h"
#include "rtsp_demo.h"

#include <QWidget>
#include <QThread>
#include <QStringList>

#include "stdint.h"
#if defined ( __cplusplus)
extern "C"
{
#include "x264.h"
};
#else
#include "x264.h"
#endif


class MainWindow;

class MediaEncIR : public QThread
{
    Q_OBJECT
public:
    explicit  MediaEncIR(QObject *parent);
    ~MediaEncIR();




    void    run() override ;
    void    Stop();
    int     GetFps() {int nRes = m_nFps; m_nFps = 0; return nRes; }

    void    EncSendOneFrame();

     MainWindow* pMainGUI;
signals:

public slots:
     void EncoderFrame(uint8_t* pImgData,int nLength,int nErrCode);

private:
    QObject*            m_parent;
    //QThreadPool         m_varThreadPool;
    int                 m_nFrameIn;
    int                 m_nFrameOut;
    QString             m_AppPath;
    volatile  qint32    m_ThreadRun;
    volatile  qint32    m_Pause;



    int                  nChannel;
    int                  nFps;

    int                  nRtspPort;
    char                 cRtspURL[STR_BUFF_LEN];
    int                  nVideoFps;
    rtsp_demo_handle     rtspInst;
    rtsp_session_handle  rtspSession;
    uint64_t             rtpPTS;
    int                  rtpPackSeq;

    int                  nOutWidth;
    int                  nOutHeight;
    volatile int         m_nFps;


    int   nHeight;
    int   nWidth;
    uint8_t*  pImg ;       //= new uint8_t[1920*1200*4];
    uint8_t*  pH265Packet; // = (uint8_t*)malloc(1920*1200*2);

    uint64_t   nPts ;

    x264_picture_t  pic_out;
    x264_picture_t  inputpic;
    x264_t *     m_hX264Enc;
    bool         m_hasSpsHead;
};

#endif // MEDIAENC_H
